// utils/logger.js
const app = getApp()

class Logger {
  constructor(pageContext) {
    this.page = pageContext
  }

  log(message) {
    const logs = this.page.data.logs || []
    logs.unshift({
      time: '',
      content: typeof message === 'object' ? JSON.stringify(message) : message
    })
    // 最多保留100条日志
    if (logs.length > 100) {
      logs.pop()
    }
    this.page.setData({ logs })
    console.log(message)
  }
}

module.exports = Logger